package com.tamecode.chapter05.part11.sub1;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration // ①将一个PoJ0标注为定义Bean的配置类
public class AppConfig {

    // ②以下两个方法定义了两个Bean,并提供了Bean的实例化逻辑
    @Bean
    public UserDao userDao() {
        return new UserDao();
    }

    @Bean
    public LogDao logDao() {
        return new LogDao();
    }

    // ③定义了logonService的Bean
    @Bean
    public LogonService logonService() {
        LogonService logonService = new LogonService();
        //④将②和③处定义的Bean注入logonService Bean中
        // 相当于在 xml 的配置中: p:logDao-ref="logDao"
        logonService.setLogDao(logDao());
        logonService.setUserDao(userDao());
        return logonService;
    }

}
